//
//  NSAttributedString+Extension.m
//  村医
//
//  Created by Mac on 2017/6/7.
//  Copyright © 2017年 WX. All rights reserved.
//

#import "NSAttributedString+Extension.h"

@implementation NSAttributedString (Extension)
+ (NSAttributedString *)yc_attributeStringWithPrefixString:(NSString *)prefixString suffixString:(NSString *)suffixString {
    
    return [self yc_attributeStringWithPrefixString:prefixString
                                         prefixFont:0
                                        prefixColor:0
                                       suffixString:suffixString
                                         suffixFont:0
                                        suffixColor:0];
}

+ (NSAttributedString *)zj_attributeStringWithPrefixString:(NSString *)prefixString
                                                prefixFont:(CGFloat)prefixFont
                                               prefixColor:(UIColor *)prefixColor
                                              suffixString:(NSString *)suffixString
                                                suffixFont:(CGFloat)suffixFont
                                               suffixColor:(UIColor *)suffixColor{
    NSInteger prefixLength = prefixString.length;
    NSInteger suffixLength = suffixString.length;
    
    NSString *finalString = [NSString stringWithFormat:@"%@%@", prefixString, suffixString];
    
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:finalString];
    
    if (prefixFont==0 && prefixColor==0) {
        [attributedString addAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRGBValue:0x999999],
                                          NSFontAttributeName: [UIFont systemFontOfSize:10.0f]
                                          }
                                  range:NSMakeRange(0, prefixLength)];
        
        
    }else {
        [attributedString addAttributes:@{NSForegroundColorAttributeName: prefixColor,
                                          NSFontAttributeName: [UIFont systemFontOfSize:prefixFont]
                                          }
                                  range:NSMakeRange(0, prefixLength)];
    }
    
    if (suffixFont==0 && suffixColor==0) {
        [attributedString addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:10.0f],
                                          NSForegroundColorAttributeName: [UIColor colorWithRGBValue:0xff786e]}
                                  range:NSMakeRange(prefixLength, suffixLength)];
    }else {
        
        
        [attributedString addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:suffixFont],
                                          NSForegroundColorAttributeName: suffixColor}
                                  range:NSMakeRange(prefixLength, suffixLength)];
    }
    
    
    return attributedString;

}

@end
